package com.wm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.wm.bean.Comment;
import com.wm.dao.CommentDao;
import com.wm.service.CommentService;
import com.wm.vo.CommentListVO;
import com.wm.vo.RestaurantListVO;

public class CommentServiceImpl implements CommentService {
	@Resource private CommentDao commentDao;
	public void setCommentDao(CommentDao commentDao) {
		this.commentDao = commentDao;
	}

	public List<Comment> listComment(Comment comment) {
		// TODO Auto-generated method stub
		String hql ="from Comment ";
		return commentDao.listComment(hql);
	}
	/**
	 * 分页展示 评论的list
	 */
	public CommentListVO listComments(CommentListVO commentListVO) {
		int maxResults = 2;
		int beginNum = (commentListVO.requestPage-1)*maxResults;

		
		commentListVO.totalPage = commentDao.getCommentPages(maxResults);
		if (commentListVO.requestPage > commentListVO.totalPage ||commentListVO.requestPage < 0) {
			beginNum = 0;
			commentListVO.requestPage = 1;
		}

		commentListVO.commentList = commentDao.getComments(beginNum,maxResults);
		
		
		return commentListVO;
	}

	public void save(Comment comment) {
		System.out.println("service");
		commentDao.save(comment);
	}

	public void update(Comment comment) {
		// TODO Auto-generated method stub

	}
	
	public CommentListVO getCommentByHql(CommentListVO commentListVO) {
		int maxResults = 10;
		int beginNum = (commentListVO.requestPage-1)*maxResults;
//System.out.println("beginNum="+beginNum);
		
		commentListVO.totalPage = commentDao.getCommentPages(maxResults);
		if (commentListVO.requestPage > commentListVO.totalPage ||commentListVO.requestPage < 0) {
			beginNum = 0;
			commentListVO.requestPage = 1;
		}
//		System.out.println("beginNum="+beginNum);
		commentListVO.commentList = commentDao.getComments(beginNum,maxResults);
		return commentListVO;
	}

}
